package com.ruicar.afs.cloud.product.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.product.entity.ProductUpdateRate;
import com.ruicar.afs.cloud.product.mapper.ProductUpdateRateMapper;
import com.ruicar.afs.cloud.product.service.ProductUpdateRateService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author changyu.gui
 * @version 1.0
 * @date 2020/5/17 21:13
 */
@Service
public class ProductUpdateRateServiceImpl extends ServiceImpl<ProductUpdateRateMapper, ProductUpdateRate> implements ProductUpdateRateService {

    @Override
    public void updateProductPlanRate(List<ProductUpdateRate> productPlanRateList, Long productPlanId) {
        //删除原有利率信息
        this.remove(Wrappers.<ProductUpdateRate>query().lambda()
                .eq(ProductUpdateRate::getProductUpdateId, productPlanId)
        );
        //保存现有的利率信息
        if (productPlanRateList.size() > 0) {
            productPlanRateList.forEach(rate -> {
                rate.setProductUpdateId(productPlanId);
            });
            this.saveBatch(productPlanRateList);
        }
    }

}
